package com.sinoglobal.ningxia.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;

/**
 * @Title: SearchPopupWindow.java
 * @Package com.sinoglobal.ningxia.widget
 * @Description: TODO(用一句话描述该文件做什么)
 * @author czz
 * @date 2014-6-23 上午10:25:46
 */
public class SearchPopupWindow extends PopupWindow {

	private View mMenuView;
	private TextView searchDialogBtn; //搜索按钮
	public EditText searchDialogEt;  //搜索内容框
	private int height;

	public SearchPopupWindow(Activity context,OnClickListener onclicklistener) {
		super(context);
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mMenuView = inflater.inflate(R.layout.search_dialog, null);
		searchDialogBtn = (TextView) mMenuView.findViewById(R.id.search_dialog_btn);
		searchDialogEt = (EditText) mMenuView.findViewById(R.id.search_dialog_et);
		searchDialogBtn.setOnClickListener(onclicklistener);
	    //设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(LayoutParams.FILL_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LayoutParams.FILL_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.PopupAnimation);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
		height = context.getWindowManager().getDefaultDisplay().getHeight();
		mMenuView.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				int ht = height - mMenuView.findViewById(R.id.pop_layout).getBottom()*2;
				int y=(int) event.getY();
				if(event.getAction()==MotionEvent.ACTION_UP){
					if(y<ht){
						dismiss();
					}
				}				
				return true;
			}
		});
	}
}
